#pragma once

#include "mqtt_client.h"

class MQTT
{
public:
    int open(const char* client_id,
             const char* username,
             const char* password,
             int         keep_alive,
             const char* host,
             int         port,
             const char* on_connected,
             const char* on_message);

    void subscribe(const char* topic, int qos);

    int publish(const char* topic, const char* payload, int qos);

    const char* get_connected_fn()
    {
        return on_connected_.c_str();
    }
    const char* get_on_message_fn()
    {
        return on_message_.c_str();
    }

private:
    mqtt_client_t* cli = NULL;

    std::string on_connected_;
    std::string on_message_;
};

MQTT* newMQTT();

using t_http_r = std::tuple<int, std::string, std::string>;
using map_ss   = std::map<std::string, std::string>;

t_http_r http_lua_call(const char* fname,
                       const char* method,
                       const char* path,
                       const char* body,
                       map_ss      headers,
                       map_ss      params);

void mqtt_lua_call(const char* fname, const char* arg1, const char* arg2);
